<template>
  <div class="app-container">
    <div class="filter-container">
      <span class="filter-title filter-item">红包状态</span>
      <k-select
        v-model="listQuery.redPacketStatus"
        class="filter-item user-status"
        type="1"
        :select-params="[{label:'已领取',value: 1},{label:'待领取',value: 2}]"
        @handleSelectEvent="handleFilter"
      />

      <span class="filter-title filter-item">所属主播</span>
      <k-select
        v-model.trim="listQuery.fissionId"
        class="filter-item right-item"
        :custom-params="{opations:belongList, label:'lineName',value:'lineId'}"
        @handleSelectEvent="handleFilter"
      />

      <span class="filter-title filter-item" style="margin-left: 20px;">领取时间</span>
      <k-date-picker
        v-model="timeValue"
        class="filter-item"
        @hqchang="handleFilter"

      />

      <k-input
        v-model.trim="listQuery.key"
        class="filter-item"
        is-search
        placeholder="请输入关键词"
        :search-fun="handleFilter"
        @keyup.enter.native="handleFilter"
      />
    </div>

    <k-button
      v-if="authorityHandle(56)"
      class="top-btn btn_copykey"
      value="一键复制"
      :data-clipboard-text="redCodeList.join('\n')"
      @click.native="oneKeyCopy"
    />

    <div v-else style="margin-top: 40px;" />

    <!--表格相关 -->
    <el-table
      :data="codeTableData"
      fit
      :show-summary="!authorityHandle(58)"
      :summary-method="getSummaries"
      border
      highlight-current-row
      style="width: 100%;border-radius:8px;"
      :header-cell-style="{background:'#F6F5FA',color:'#4E4F62'}"
    >
      <el-table-column width="80px" type="index" label="序号" align="center" />
      <el-table-column prop="amount" min-width="80px" label="红包金额（F）" align="center" show-overflow-tooltip />
      <el-table-column prop="userMobile" min-width="80px" label="领取人用户名" align="center" show-overflow-tooltip />
      <el-table-column prop="userName" min-width="80px" label="领取人昵称" align="center" show-overflow-tooltip />
      <el-table-column prop="receiveTime" min-width="100px" label="领取时间" align="center" show-overflow-tooltip />
      <el-table-column prop="receiveStatusName" min-width="100px" label="红包状态" align="center" show-overflow-tooltip />
      <el-table-column min-width="100px" label="生效时间" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.startTime }} - {{ scope.row.endTime }}
        </template>
      </el-table-column>
      <el-table-column prop="envelopePassword" min-width="90px" label="红包码" align="center" />
      <el-table-column prop="fissionName" min-width="90px" label="所属主播" align="center" />
    </el-table>
    <pagination
      v-show="totalRows > 0"
      :total="totalRows"
      :page.sync="listQuery.pager.pageNo"
      :limit.sync="listQuery.pager.pageSize"
      @pagination="loadData"
    />

  </div>
</template>
<script>
import { getSinglePasswordList, listSingleItemData } from '@/api/red/data'
import Pagination from '@/components/Pagination'
import ClipboardJS from 'clipboard'
import { getAnchors } from '@/api/user/user'
export default {
  components: { Pagination },
  data() {
    return {
      signRedpocketSwitch: 1,
      totalRows: 0,
      amount: 0,
      listQuery: {
        pager: {
          pageNo: 1,
          pageSize: 10,
          totalRows: '',
          start: ''
        },
        sort: '', // 排序字段 为对应列名,
        direction: '', // 排序 正向(asc)逆向(desc),
        startTime: undefined, // 饰品外观',
        endTime: undefined, // 饰品类别',
        key: '', // 箱子名称或关键词 箱子配置界面所用'
        redPacketStatus: undefined, // 红包状态',
        envelopeId: undefined, // 多码红包详情页为红包id，主播红包为主播id'
        fissionId: undefined
      },
      codeTableData: [],
      redCodeList: [],
      ruleGuideContent: {
        content: ''
      },
      signRedSettingItemList: [{
        id: undefined,
        minAmount: undefined,
        maxAmount: undefined,
        probability: undefined
      }],
      envelopeId: '',
      timeValue: '',
      conditions: {
        keyword: null
      },
      belongList: []
    }
  },
  watch: {
    // 时间赋值
    timeValue(val) {
      this.listQuery.startTime = this.timeValue ? this.timeValue[0] : null
      this.listQuery.endTime = this.timeValue ? this.timeValue[1] : null
    }
  },
  created() {
    this.getAnchors()
  },
  methods: {
    // 获取主播
    getAnchors() {
      getAnchors().then(res => {
        this.belongList = res.data.data
        this.loadData()
      })
    },

    getSummaries(param) {
      const { columns } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) { // 第一列
          sums[index] = '总计'
        } else if (column.property === 'amount') {
          sums[index] = this.amount
        } else {
          sums[index] = ''
        }
      })
      return sums
    },
    loadData() {
      this.envelopeId = this.$route.query.id
      this.listQuery.envelopeId = Number(this.envelopeId)
      this.listSingleItemData()
      this.getSinglePasswordList()
    },
    listSingleItemData() {
      listSingleItemData(this.listQuery).then(res => {
        this.totalRows = res.data.totalRows
        this.amount = res.data.totalData
        this.codeTableData = res.data.rows
      })
    },
    getSinglePasswordList() {
      getSinglePasswordList({ 'envelopeId': this.envelopeId, ...this.listQuery }).then(res => {
        this.redCodeList = res.data
      })
    },
    oneKeyCopy() {
      const clipboard = new ClipboardJS('.btn_copykey')
      clipboard.on('success', e => {
        this.$message.success('复制成功')
        //  释放内存
        e.clearSelection()
        clipboard.destroy()
      })
      clipboard.on('error', e => {
        // 不支持复制
        this.$message.error('复制出错')
        clipboard.destroy()
      })
    },
    // 搜索查询事件
    handleFilter() {
      this.listQuery.pager.pageNo = 1
      this.listSingleItemData()
      this.getSinglePasswordList()
    },

    ruleGuideDialog() {
      this.ruleGuide.showHide = true
    }
  }

}
</script>
<style lang="scss" scoped>
$menuText:#14162E; // 侧边栏字体颜色
$hoverColor:#79BBFF;// 鼠标停留主色调浅色
$mainColor:#409EFF;// 主色调
.filter-container {
  width: 100%;
  height: 48px;
  line-height: 48px;
  .filter-item {
    display: inline-block;
    vertical-align: middle;
    margin-bottom: 10px;
  }
  .kInput{
    position:absolute;
    right: 20px;
  }
  .filter-title{
    height: 48px;
    line-height: 48px;
    font-size: 16px;
    font-weight: 500;
    margin-right: 22px;
    color: #14162E;
  }
  .user-item {
    margin-left: 10px;
    margin-right: 20px;
  }
  .room-type,.user-status,.account-status{
    margin-right: 20px;
  }
}
.red_money{
  width: 200px;
}
.grid-div{
  display: grid;
  grid-template-columns:  repeat(7, 120px);
  .item{
    height: 50px;
    font-size: 14px;
    line-height:50px;
    text-align: center;
    border: 1px solid #E3E2E7;
    width: 120px;
    overflow: hidden;
    display: inline-block;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 10px;
  }
}
.top-btn{
  margin: 30px 0px 30px 0px;
  font-size: 14px;
  color: #ffffff;
   &:nth-of-type(2){
    margin-left: 10px;
  }
}
.kSelect .el-select .el-input .el-input__inner{
  width: 124px;
}
::v-deep .el-select .el-input.is-focus .el-input__inner {
    border-color: $mainColor;
}
::v-deep .el-input__inner:focus {
    border-color: $mainColor;
}
.el-form-item__label-wrap .el-form-item__label{
  float: none;
}

.dialog_creatRollRoom{
  display: flex;
  flex-direction: row;
  justify-content: center;
  margin: 40px 80px;
  ::v-deep .el-select .el-select__tags>span {
			display: none;
	}
  .el-tag + .el-tag {
    margin-left: 10px;
  }
   .el-tag {
    color: $mainColor;
    background-color: #ffffff;
    border-color: $mainColor;
    ::v-deep .el-tag__close {
      color: $mainColor;
    }
    ::v-deep .el-icon-close:hover {
      color:#ffffff;
      background: $mainColor;
    }
  }
}

.form-modify{
  display: flex;
  flex-direction: row;
  justify-content: center;
  margin: 10px 80px;
}

.editer {
  width: 500px;
  border-radius: 8px;
  float: left;
  box-sizing: border-box;
  color: #606266;
  ::v-deep .ql-container {
    height: 270px;
    border-radius: 0px 0px 8px 8px;
  }
  ::v-deep .ql-toolbar.ql-snow {
    border-radius: 8px 8px 0px 0px;
  }
}
.chargeform{
  display: flex;
  flex-direction: row;
}

::v-deep .el-switch__label.is-active {
    color: $mainColor;
}

.addBox_dialog{
  display: flex;
  flex-direction: column;
  justify-content: center;
  ::v-deep .el-dialog__body{
    width: 678px;
    margin: 40px 80px;
 }
::v-deep .el-select .el-select__tags>span {
			display: none;
	}
  .el-tag + .el-tag {
    margin-left: 10px;
  }
   .el-tag {
    color: $mainColor;
    background-color: #ffffff;
    border-color: $mainColor;
    ::v-deep .el-tag__close {
      color: $mainColor;
    }
    ::v-deep .el-icon-close:hover {
      color:#ffffff;
      background: $mainColor;
    }
  }
}
.el_switch_top{
  margin: 30px 0px 30px 0px;
  position: absolute;
  right: 20px;
}

.set_box {
    width: 700px;
    margin: 0 80px;
    box-sizing: border-box;
    .Recharge_Data {
      width: 100%;
      height: 40px;
      margin-top: 10px;
      display: flex;
      align-items: center;
      .Recharge_Data_box {
        width: 100%;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .el-input {
          width: 150px;
          height: 35px;
          input {
            width: 150px;
            height: 35px;
          }
        }
        span {
          font-size: 14px;
          width: 100px;
        }
      }
      .operation {
        width: 12%;
        display: flex;
        justify-content: space-between;
        .el-icon{
            &-circle-plus, &-remove{
              font-size: 22px;
              color:#3b425d;
              margin-left: 10px;
          }
        }
      }
     }
 }
</style>
